package com.qf.index;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Guidelines {

    /**
     * 部分指南，在前端显示标题、作者、来源为空，比如：39946521 39946518，这种一般是图书的章节，让福磊判断一下，如果两项为空，就不给前端返回了。
     * 2025.04.12
     */
    public static void main(String[] args) throws SQLException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(format.format(new Date()) + " 程序开始了~~~");
        String summaryTable = "scholar_25_01.pm_ut_aid_info_1218";
        String citationTable = "scholar_25_01.basic_core_paper_citation";
        String referenceTable = "scholar_25_01.basic_core_paper_reference_id";
        String guidelinesTable = "scholar_25_01.pm_ut_aid_info_1218_guidelines";
        String deptTable = "scholar_25_01.pm_ut_aid_info_1218_guidelines_dept_copy1";
        String hospTable = "scholar_25_01.pm_ut_aid_info_1218_guidelines_hosp";
        String basicDeptTable = "scholar_25_01.tb_true_china_hosp_6_year_dept";
        String basicHospTable = "scholar_25_01.tb_true_china_hosp_6_year_hosp";
        String cnBasicDeptTable = "scholar_25_01.cn_dept_sum_dy30";
        String basicUnivCollTable = "scholar_25_01.basic_univ_coll";
        String htLocationChinaTable = "scholar_25_01.ht_location_china";
        String basicHospUnivDeptTable = "scholar_25_01.basic_hosp_or_univ_dept";

        // 将PubMed官网下载的临床指南（按Guideline限定）的数据导入到表中，作为临床指南的源数据。
        String filePath = "F:\\WorkSpaces\\Data\\src\\main\\resources\\dict\\2015年及以来PubMed收录的临床指南_按Guideline限定_共13870条_2025_02_27.txt";

        String newDataName = "scholar_25_02.";
        String ncTextTable = "html.nc_text_table";
        String ncTextGuidelineTable = "html.nc_text_table_guideline";
        String user = "Bearer sk-c65ee8baf0c440238e51f74495107da3";

        // 根据手工下载的临床指南集合（共13870条），获取临床指南源数据表
        getGuidelineTable(ncTextTable, ncTextGuidelineTable, filePath);

        // 依据临床指南的标题和摘要，通过通义推荐复旦和STEM的学科名称。
        updateGuideline(ncTextGuidelineTable, "id", "ti`,`ab`,`fudan`,`stem`,`you_dao", user, 0, 99);

        // 依据临床指南论文的作者信息，获取临床指南的发颁机构、国家和年份。
        updateCountry(ncTextGuidelineTable, "id", "auList`,`dp`,`country", user, 0, 99);

    }

    public static void updateCountry(String ncTextGuidelineTable, String autoId, String field, String user, int min, int max) throws SQLException {
        int onePageNum = 1000;
        int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + ncTextGuidelineTable).intValue();
        if (tableMax > 0) {
            Collection<Integer> tableList = new ArrayList<>();
            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
            for (Integer startId : tableList) {
                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + ncTextGuidelineTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
                for (Entity entry : tableData) {
                    String aus = entry.getStr("auList");
                    int id = Utils.getIntField(entry, autoId);
                    int end = id > 10 ? Integer.parseInt(Integer.toString(id).substring(Integer.toString(id).length() - 2)) : id;
                    String country = Utils.getStrField(entry, "country");
                    country = "[]".equals(country) ? "" : country;
                    if (null != aus && aus.contains("adList") && id > 0 && (end >= min && end <= max) && (country.isEmpty() || "1".equals(country) || "2".equals(country) || "3".equals(country) || "4".equals(country))) {
                        List<En.UCHSDC> uchsdcList = new ArrayList<>();
                        List<String> institutionList = new ArrayList<>();
                        List<String> countryList = new ArrayList<>();
                        List<En.AU> auList = JSONObject.parseArray(aus, En.AU.class);
                        for (En.AU au : auList) {
                            List<String> adList = au.getAdList();
                            for (String info : adList) {
                                addUchsdcList(user, info, uchsdcList, institutionList, countryList, id);
                            }
                        }
                        String dp = Utils.getStrField(entry, "dp");
                        int year = 1900;
                        if (Pattern.compile("^19|20[0-9]{2}").matcher(dp).find()) {
                            year = NumberUtil.isInteger(dp.substring(0, 4)) ? Integer.parseInt(dp.substring(0, 4)) : year;
                        }
                        if (countryList.isEmpty()) {
                            if (country.isEmpty()) {
                                country = "1";
                            } else if ("1".equals(country)) {
                                country = "2";
                            } else if ("2".equals(country)) {
                                country = "3";
                            } else if ("3".equals(country)) {
                                country = "4";
                            } else if ("4".equals(country)) {
                                country = "5";
                            }
                        } else {
                            country = JSONUtil.toJsonStr(countryList);
                        }
                        try {
                            Db.use().update(
                                    Entity.create().set("country", country)
                                            .set("institution", JSONUtil.toJsonStr(institutionList))
                                            .set("year", year)
                                            .set("original", JSONUtil.toJsonStr(uchsdcList)),
                                    Entity.create(ncTextGuidelineTable).set(autoId, id));
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }

    public static void addUchsdcList(String user, String info, List<En.UCHSDC> uchsdcList, List<String> institutionList, List<String> countryList, int id) {
        info = info.replace("&#x27;", "'").replace("&amp;quot;", "\"").replace("&quot;", "\"").replace("&amp;", "&")
                .replaceAll("(?i)University of California, Berkeley", "University of California Berkeley").replaceAll("(?i)University of California, Davis", "University of California Davis")
                .replaceAll("(?i)University of California, Irvine", "University of California Irvine").replaceAll("(?i)University of California, La Jolla", "University of California La Jolla")
                .replaceAll("(?i)University of California, Los Angeles", "University of California Los Angeles").replaceAll("(?i)University of California, San Diego", "University of California San Diego")
                .replaceAll("(?i)University of California, San Francisco", "University of California San Francisco").replaceAll("(?i)University of California, Riverside", "University of California Riverside")
                .replaceAll("(?i)Charité - Universitätsmedizin, Berlin", "Charité - Universitätsmedizin Berlin").replaceAll("(?i)Charité, University Medicine Berlin", "Charité University Medicine Berlin")
                .replaceAll("(?i)Charité Universitätsmedizin, Berlin", "Charité Universitätsmedizin Berlin").replaceAll("(?i)Charité University Hospital, Berlin", "Charité University Hospital Berlin")
                .replaceAll("(?i)Charité-Universitätsmedizin, Berlin", "Charité-Universitätsmedizin Berlin").replaceAll("(?i)Universitätsmedizin Berlin, Charité", "Universitätsmedizin Berlin Charité")
                .replaceAll("(?i)Charité University Medical Center, Berlin", "Charité University Medical Center Berlin").replaceAll("(?i)Charité. University Medicine, Berlin", "Charité University Medicine Berlin");
        String[] split = info.replace("，", ";").replace("。", ";").replace(", ", ";").split(";");
        List<En.OrderInfo> orderInfoList = new ArrayList<>();
        Map<String, String> orderAndInfoMap = new HashMap<>();
        for (int i = 0; i < split.length; i++) {
            String s = reStr(split[i]);
            if (s.length() > 2) {
                En.OrderInfo orderInfo = new En.OrderInfo();
                orderInfo.setOrder(i);
                orderInfo.setInfo(s);
                orderInfoList.add(orderInfo);
                orderAndInfoMap.put(Integer.toString(i), s);
            }
        }
        String t = JSONUtil.toJsonStr(orderInfoList);
        String send = "国际临床指南，一般都是有各国的卫生管理机构或行业学会，或者医疗行业的组织或大学编写的，比如署名信息为：\"[{\"order\":0,\"info\":\"Department of Hematopathology\"},{\"order\":1,\"info\":\"University of Texas\"},{\"order\":2,\"info\":\"MD Anderson Cancer Center\"},{\"order\":3,\"info\":\"Houston\"}," +
                "{\"order\":4,\"info\":\"Texas\"},{\"order\":5,\"info\":\"ACC/AHA Representative\"},{\"order\":6,\"info\":\"Department of Pathology\"},{\"order\":7,\"info\":\"University of Texas Medical Branch\"},{\"order\":8,\"info\":\"Galveston\"},{\"order\":9,\"info\":\"Texas.\"}]\"（为了方便回答问题，" +
                "我给各部分内容分了段(info)，并加上了序号(order)），里面包含了大学（University of Texas），医学部或医学院或医学中心（University of Texas Medical Branch），医疗机构（MD Anderson Cancer Center），行业学会（ACC/AHA Representative），负责的科室（Department of Hematopathology）以及负责的国家（在署名中虽然部分没有明确指出具体的" +
                "国家，但我们通过大学或医学院或医疗机构或行业学会，也可以推断出来是美国），但有些署名信息没有这么全，可能只有医疗机构或行业学会等。另外，部分大学的名称中虽然没有\"University\"字样，比如\"california institute of technology\"、\"trinity college dublin\"、\"eth zurich\"等仍然应该归属到大学中。部分医疗机构的名称中也没有\"Hospital\"字样，" +
                "比如：\"sheba medical center\"、\"nacional jewish health\"、\"mayo clinical\"等仍然应该归属到医疗机构中。大部分的行业学会的名称中也没有\"society\"字样，比如：\"japanese gastroenterological association\"、\"medicines and healthcare products regulatory agency\"、\"europa donna-the european breast cancer coalition\"等，" +
                "在这里我们定义行业学会为：有能力组织和编写临床指南的卫生管理机构、行业学会，或者针对某种疾病的联盟、研究所、基金会、研究中心、医疗中心、协会、学会等，均可以归属到行业学会，但明确的大学或医疗机构不能归属到行业学会。基于此分析，请问署名为：\"" + t + "\" 的作者信息，它的大学、医学部或医学院或医学中心、医疗机构、行业学会、负责的科室、负责的国家分别是什么？" +
                "返回格式要求是标准的JSON，格式要求: \"{\"university\":\"1\",\"college\":\"7\",\"hospital\":\"2\",\"society\":\"5\",\"department\":\"0\",\"country\":\"美国\"}\"，具体的内容请使用序号，国家名称应是标准的中文名称，并且国家名称不能为空，有多个大学或医学院或医疗机构的，只返回第一个出现的，没有匹配上的内容请返回\"-1\"，当大学或医学院" +
                "或医疗机构没有匹配上时，切记不可以使用一个国家或城市的名称来代替，提供的info中如果同时包含\"University\"和\"Hospital\"的，应归属到医疗机构中，提供的info中如果同时包含大学（或医疗机构）和负责的科室的，比如：\"Director of the Division of Gastroenterology at McMaster University in Hamilton\"，应归属到大学（或医疗机构）。";
        String api = TongYiApi.api(send, user);
        En.UCHSDC uchsdc = new En.UCHSDC();
        Matcher uMatcher = Pattern.compile("\"university\"\\s*:\\s*\"([^\"]*)\"").matcher(api);
        Matcher cMatcher = Pattern.compile("\"college\"\\s*:\\s*\"([^\"]*)\"").matcher(api);
        Matcher hMatcher = Pattern.compile("\"hospital\"\\s*:\\s*\"([^\"]*)\"").matcher(api);
        Matcher sMatcher = Pattern.compile("\"society\"\\s*:\\s*\"([^\"]*)\"").matcher(api);
        Matcher dMatcher = Pattern.compile("\"department\"\\s*:\\s*\"([^\"]*)\"").matcher(api);
        Matcher oMatcher = Pattern.compile("\"country\"\\s*:\\s*\"([^\"]*)\"").matcher(api);
        String university = uMatcher.find() ? uMatcher.group(1).trim() : "";
        String college = cMatcher.find() ? cMatcher.group(1).trim() : "";
        String hospital = hMatcher.find() ? hMatcher.group(1).trim() : "";
        String society = sMatcher.find() ? sMatcher.group(1).trim() : "";
        String department = dMatcher.find() ? dMatcher.group(1).trim() : "";
        String country = oMatcher.find() ? oMatcher.group(1).trim() : "";
        uchsdc.setUniversity(orderAndInfoMap.getOrDefault(university, ""));
        uchsdc.setCollege(orderAndInfoMap.getOrDefault(college, ""));
        uchsdc.setHospital(orderAndInfoMap.getOrDefault(hospital, ""));
        uchsdc.setSociety(orderAndInfoMap.getOrDefault(society, ""));
        uchsdc.setDepartment(orderAndInfoMap.getOrDefault(department, ""));
        uchsdc.setCountry(country);
        uchsdc.setInfo(info);
        uchsdcList.add(uchsdc);
        if (uchsdc.getHospital().isEmpty() && uchsdc.getUniversity().isEmpty() && uchsdc.getCollege().isEmpty() && uchsdc.getSociety().isEmpty()) {
            for (En.OrderInfo orderInfo : orderInfoList) {
                String s = orderInfo.getInfo();
                if (s.toLowerCase().contains("hospital") && s.length() > 12) {
                    uchsdc.setHospital(s);
                } else if (s.toLowerCase().contains("university") && s.length() > 14) {
                    uchsdc.setUniversity(s);
                }
            }
            uchsdc.setUniversity(uchsdc.getHospital().equals(uchsdc.getUniversity()) ? "" : uchsdc.getUniversity());
        }
        String institution = !uchsdc.getHospital().isEmpty() ? uchsdc.getHospital() : "";
        institution = institution.isEmpty() && !uchsdc.getUniversity().isEmpty() ? uchsdc.getUniversity() : institution;
        institution = institution.isEmpty() && !uchsdc.getCollege().isEmpty() ? uchsdc.getCollege() : institution;
        institution = institution.isEmpty() && !uchsdc.getSociety().isEmpty() ? uchsdc.getSociety() : institution;
        if (!institution.isEmpty()) {
            if (!country.isEmpty() && !countryList.contains(country)) {
                countryList.add(country);
            }
            if (!institutionList.contains(institution)) {
                institutionList.add(institution);
            }
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("uchsdc.getHospital():" + uchsdc.getHospital());
        System.out.println("uchsdc.getUniversity():" + uchsdc.getUniversity());
        System.out.println("uchsdc.getCollege():" + uchsdc.getCollege());
        System.out.println("uchsdc.getSociety():" + uchsdc.getSociety());
        System.out.println(format.format(new Date()) + " " + id + ": " + "info:" + info + " country:" + country + " institution:" + institution);
    }

    public static String reStr(String info) {
        String t = info.replace("&quot,", "\"").trim();
        t = t.endsWith(".") ? t.substring(0, t.length() - 1).trim() : t;
        t = t.toLowerCase().endsWith("&amp;quot") ? t.substring(0, t.length() - "&amp;quot".length()) + "\"".trim() : t;
        t = t.toLowerCase().endsWith("&quot") ? t.substring(0, t.length() - "&quot".length()) + "\"".trim() : t;
        t = t.toLowerCase().endsWith("&amp") ? t.substring(0, t.length() - "&amp".length()).trim() : t;
        t = t.toLowerCase().startsWith("the ") ? t.substring("the ".length()).trim() : t;
        while (true) {
            String s = t.toLowerCase();
            if (s.startsWith("‡") || s.startsWith(" ") || s.startsWith("§") || s.startsWith("ǁ") || s.startsWith("*") || s.startsWith("-") || s.startsWith(".") || s.startsWith("#") || s.startsWith("¶") ||
                    s.startsWith(")") || s.startsWith("$") || s.startsWith("/") || s.startsWith("\\") || s.startsWith("‖") || s.startsWith("’") || s.startsWith("†")) {
                t = t.substring(1).trim();
            } else {
                break;
            }
        }
        return t.replaceAll(" +", " ").trim();
    }

    public static void updateGuideline(String ncTextGuidelineTable, String autoId, String field, String user, int min, int max) throws SQLException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int onePageNum = 1000;
        Set<String> fuDanSet = uSet.getFuDanSet();
        Set<String> stemSet = uSet.getStemSet();
        String fuDans = "病理科,传染感染,耳鼻喉科,放射科,呼吸科,风湿病,妇产科,骨科,精神医学,口腔科,麻醉科,泌尿外科,内分泌,皮肤科,普通外科,神经内科,肾脏病,神经外科,消化病,小儿内科,小儿外科,心血管病,心外科,胸外科,血液学,眼科,整形外科,肿瘤学,老年医学,康复医学,检验医学,烧伤科,核医学,超声医学,急诊医学,重症医学,临床药学,生殖医学,变态反应,健康管理,结核病,全科医学,疼痛学,运动医学,罕见病";
        String stems = "麻醉学,心血管病学,呼吸病学,结核病学,消化病学,血液病学,肾脏病学,内分泌病学与代谢病学,风湿病学与自体免疫病学,变态反应学,传染病学,普通外科学,神经外科学,超声医学,放射学,核医学,护理学,肿瘤学,急诊医学,危重症医学,精神病学,神经病学,皮肤病学,口腔医学,耳鼻喉科学,眼科学,儿科学,妇产科学,整形外科学,烧伤外科学,骨外科学,泌尿外科学,心血管外科学,胸外科学";
        int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + ncTextGuidelineTable).intValue();
        if (tableMax > 0) {
            Collection<Integer> tableList = new ArrayList<>();
            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
            for (Integer startId : tableList) {
                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + ncTextGuidelineTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
                for (Entity entry : tableData) {
                    String ti = Utils.getStrField(entry, "ti");
                    String ab = Utils.getStrField(entry, "ab");
                    String fuDan = Utils.getStrField(entry, "fudan");
                    String stem = Utils.getStrField(entry, "stem");
                    String youDao = Utils.getStrField(entry, "you_dao");
                    int id = Utils.getIntField(entry, autoId);
                    int end = id > 10 ? Integer.parseInt(Integer.toString(id).substring(Integer.toString(id).length() - 2)) : id;
                    if ((fuDan.isEmpty() || "1".equals(fuDan) || "2".equals(fuDan) || stem.isEmpty() || "1".equals(stem) || "2".equals(stem)) && id > 0 && (end >= min && end <= max) && (ti.length() > 3 || ab.length() > 3)) {
                        try {
                            youDao = youDao.startsWith("[") && youDao.endsWith("].") ? youDao.substring(1, youDao.length() - 2) : youDao;
                            youDao = youDao.length() < 4 ? TransApi.youDaoEnToCnTrans(ti) : youDao;
                            String upDataFuDan = getGuidelineUpData(fuDan, ti, ab, user, fuDanSet, fuDans);
                            String upDataStem = getGuidelineUpData(stem, ti, ab, user, stemSet, stems);
                            System.out.println(format.format(new Date()) + " " + id + ": " + "--fuDan--" + upDataFuDan + "--stem--" + upDataStem + "~~~~" + youDao);
                            try {
                                Db.use().update(Entity.create().set("fudan", upDataFuDan).set("stem", upDataStem).set("you_dao", youDao).set("datetime", LocalDateTime.now()), Entity.create(ncTextGuidelineTable).set(autoId, id));
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
                        } catch (Exception e) {
//                                throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }

    public static String getGuidelineUpData(String fuDan, String ti, String ab, String user, Set<String> fuDanSet, String fuDanOrStem) {
        if (fuDan.isEmpty() || "1".equals(fuDan) || "2".equals(fuDan) || "3".equals(fuDan)) {
            String send = "临床指南是基于当前最佳的科学证据和专家共识制定的一系列推荐意见，旨在帮助医疗专业人员做出更加合理和有效的诊疗决策，不同的临床指南适用与不同的科室或学科，部分临床指南，也可能适用于多个科室或学科。临床指南一般以论文的形式公开发表，部分仅从论文的标题上，即可区分该临床指南适用于哪个科室或学科，" +
                    "有些还需要通过论文的摘要才可以区分出来。基于此，请问论文标题为：\"+" + ti + "+\"，论文摘要为：\"+" + ab + "+\" 的这篇临床指南，应该适用于标准科室或学科清单：\"" + fuDanOrStem + "\" 中的哪个科室或学科？如果适用于多个科室或学科，请按重要程度回答，并返回重要程度排在最前面的三个科室或学科，" +
                    "如果仅适用于一个，则只返回一个，如果仅适用于二个，则只返回二个。返回格式要求是标准的JSON，返回的科室或学科必须是在我提供的清单中，格式要求:\" + \"{\"subject_1\":\"妇产科\",\"subject_2\":\"传染病学\",\"subject_3\":\"\"}\")";
            String api = TongYiApi.api(send, user);
            Matcher aMatcher = Pattern.compile("\"subject_1\"\\s*:\\s*\"([^\"]*)\"").matcher(api);
            Matcher bMatcher = Pattern.compile("\"subject_2\"\\s*:\\s*\"([^\"]*)\"").matcher(api);
            Matcher cMatcher = Pattern.compile("\"subject_3\"\\s*:\\s*\"([^\"]*)\"").matcher(api);
            String a = (aMatcher.find()) ? aMatcher.group(1).trim() : "";
            String b = (bMatcher.find()) ? bMatcher.group(1).trim() : "";
            String c = (cMatcher.find()) ? cMatcher.group(1).trim() : "";
            List<String> fuDanList = new ArrayList<>();
            if (fuDanSet.contains(a)) {
                fuDanList.add(a);
            }
            if (fuDanSet.contains(b)) {
                fuDanList.add(b);
            }
            if (fuDanSet.contains(c)) {
                fuDanList.add(c);
            }
            String upData = "";
            if (fuDanList.isEmpty()) {
                if (fuDan.isEmpty()) {
                    upData = "1";
                } else if ("1".equals(fuDan)) {
                    upData = "2";
                } else if ("2".equals(fuDan)) {
                    upData = "3";
                }
            } else {
                upData = JSONUtil.toJsonStr(fuDanList);
            }
            return upData;
        }
        return fuDan;
    }

    public static void getGuidelineTable(String ncTextTable, String ncTextGuidelineTable, String filePath) throws SQLException {
        Set<Integer> guidelinesPmIdSet = getGuidelinesPmIdSet(filePath);
        Db.use().execute("truncate table " + ncTextGuidelineTable);
        String save = "`aidList`,`mhList`,`isList`,`ptList`,`rnList`,`otList`,`laList`,`plList`,`lidList`,`grList`,`siList`,`oidList`,`conList`,`cinList`,`cnList`,`einList`,`gnList`,`iradList`,`efrList`,`gsList`,`pbList`,`uofList`,`uinList`,`rofList`," +
                "`rinList`,`sfmList`,`isbnList`,`rpfList`,`rpiList`,`ecfList`,`eciList`,`crfList`,`criList`,`oriList`,`spinList`,`drinList`,`ddinList`,`rrfList`,`auList`,`phstList`,`stat`,`dp`,`crdt`,`edat`,`ti`,`so`,`jt`,`pst`,`jid`,`lr`,`own`,`mhda`," +
                "`ta`,`pmid`,`vi`,`pg`,`dcom`,`ip`,`sb`,`ab`,`dep`,`oto`,`pmc`,`pmcr`,`ci`,`cois`,`ir`,`fir`,`tt`,`rf`,`mid`,`fps`,`ps`,`oab`,`oabl`,`fed`,`ed`,`bti`,`ctdt`,`cti`,`cp`,`drdt`,`en`,`rriList`";
        for (Integer pmId : guidelinesPmIdSet) {
            Db.use().execute("insert into " + ncTextGuidelineTable + " (" + save + ") SELECT " + save + " from " + ncTextTable + " where pmid = " + pmId + ";");
        }
    }

    public static Set<Integer> getGuidelinesPmIdSet(String filePath) {
        Set<Integer> guidelinesPmIdSet = new HashSet<>();
        List<String> list = FileUtil.readLines(filePath, "utf-8");
        for (String s : list) {
            String[] split = s.split("\\|");
            String pm = split.length == 2 ? split[0] : "";
            pm = split.length == 1 ? split[0] : pm;
            if (NumberUtil.isInteger(pm)) {
                guidelinesPmIdSet.add(Integer.parseInt(pm));
            }
        }
        return guidelinesPmIdSet;
    }

//    public static void insertAdInfoSumTable(String ncTextTable, String autoId, String field, String adInfoSumTable,String filePath) throws SQLException {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Set<Integer> guidelinesPmIdSet = getGuidelinesPmIdSet(filePath);
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + ncTextTable);
//        Set<String> subjectSet = cList.getSubjectSet();
//        Set<String> removeSet = uSet.getRemoveSet();
//        Set<String> hospSet = uSet.getHospSet();
//        Set<String> univSet = uSet.getUnivSet();
//        Db.use().execute("truncate table " + adInfoSumTable);
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + ncTextTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + ncTextTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                System.out.println("\033[31;1m" + format.format(new Date()) + " 读表现在开始：" + startId + " 表名：" + ncTextTable + Utils.printMemoryStr() + "\033[0m");
//                for (Entity entry : tableData) {
//                    String aus = entry.getStr("auList");
//                    Integer pmId = entry.getInt("pmid");
//                    if (null != aus && aus.contains("adList") && null != pmId && guidelinesPmIdSet.contains(pmId)) {
//                        List<En.AU> auList = JSONObject.parseArray(aus, En.AU.class);
//                        for (En.AU au : auList) {
//                            List<String> adList = au.getAdList();
//                            for (String info : adList) {
//                                info = info.replace("&#x27;", "'").trim();
//                                String[] split = info.replace("，", ",").replace("。", ".").split(", ");
//                                Set<String> univs = new HashSet<>();
//                                Set<String> hosps = new HashSet<>();
//                                Set<String> colls = new HashSet<>();
//                                for (String s : split) {
//                                    s = s.trim();
//                                    Set<String> depts = new HashSet<>();
//                                    Dept.getEnDept(s, depts, subjectSet, removeSet);
//                                    boolean isEnUniv = Unit.isUniv(s, univSet, removeSet);
//                                    boolean isEnHosp = Unit.isHosp(s, hospSet, removeSet);
//                                    if (isEnUniv) {
//                                        univs.add(s);
//                                    }
//                                    if (isEnHosp) {
//                                        hosps.add(s);
//                                    }
//                                    if (!depts.isEmpty()) {
//                                        colls.addAll(depts);
//                                    }
//                                }
//                                int isUnit = (!univs.isEmpty() || !hosps.isEmpty() || !colls.isEmpty()) ? 1 : 0;
//                                try {
//                                    Db.use().insert(Entity.create(adInfoSumTable).set("info", info).set("pmId", pmId).set("is_nuit", isUnit).set("univ", JSONUtil.toJsonStr(univs)).set("hosp", JSONUtil.toJsonStr(hosps)).set("coll", JSONUtil.toJsonStr(colls)));
//                                } catch (SQLException e) {
//                                    e.printStackTrace();
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//        }
//    }

//    public static void updateDept(String guidelinesTable, String autoId, String field, String deptTable) throws SQLException {
//        // 根据人工加AI翻译后的科室名称，保存进实体类，要求科室名称必须是复旦或STEM的标准名称。deptTable是人工加AI翻译后科室信息。
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Set<String> fuDanSet = uSet.getFuDanSet();
//        Set<String> stemSet = uSet.getStemSet();
//        Map<String, List<String>> deptAndFuDanOrStemListMap = new HashMap<>();
//        Guidelines.getEnDeptAndFuDanOrStemListMap(deptTable, "id", "info`,`fudan`,`stem", stemSet, fuDanSet, deptAndFuDanOrStemListMap);
////        Guidelines.getCnDeptAndFuDanOrStemListMap(cnBasicDeptTable, "id", "info`,`fudan`,`stem", stemSet, fuDanSet, deptAndFuDanOrStemListMap);
//        deptAndFuDanOrStemListMap = Guidelines.mapSortValueStrLen(deptAndFuDanOrStemListMap);
////        Map<String, List<String>> deptAndFuDanOrStemListMap = getEnDeptAndFuDanOrStemListMap(deptTable, "id", "info`,`fudan`,`stem", stemSet, fuDanSet);
//        System.out.println(format.format(new Date()) + " deptAndFuDanOrStemListMap.size()：" + deptAndFuDanOrStemListMap.size());
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + guidelinesTable);
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + guidelinesTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + guidelinesTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                System.out.println("\033[31;1m" + format.format(new Date()) + " 读表现在开始：" + startId + " 表名：" + guidelinesTable + Utils.printMemoryStr() + "\033[0m");
//                for (Entity entry : tableData) {
//                    List<En.C1Auth> c1List = upDataC1List(deptAndFuDanOrStemListMap, stemSet, fuDanSet, entry.getStr("c1_unit_dept_auth"));
//                    List<En.C1Auth> rpChangeC1 = upDataC1List(deptAndFuDanOrStemListMap, stemSet, fuDanSet, entry.getStr("rp_unit_dept_auth"));
//                    int id = Utils.getIntField(entry, autoId);
//                    try {
//                        Db.use().update(Entity.create().set("c1_unit_dept_auth", JSONUtil.toJsonStr(c1List)).set("rp_unit_dept_auth", JSONUtil.toJsonStr(rpChangeC1)), Entity.create(guidelinesTable).set(autoId, id));
//                    } catch (SQLException e) {
//                        e.printStackTrace();
//                    }
//                }
//            }
//        }
//    }

//    public static List<En.C1Auth> upDataC1List(Map<String, List<String>> deptAndFuDanOrStemListMap, Set<String> stemSet, Set<String> fuDanSet, String c1OrRp) {
//        // 更新实体类，先获取本次的，再与人工加AI翻译的结果deptAndFuDanOrStemListMap进行比对，比对上后给予合并，最后再只保留复旦或STEM的标准名称后返回。
//        if (null != c1OrRp && c1OrRp.contains("info")) {
//            List<En.C1Auth> c1AuthList = JSONObject.parseArray(c1OrRp, En.C1Auth.class);
//            for (En.C1Auth c1Auth : c1AuthList) {
//                Set<String> depts = c1Auth.getDeptSet();
//                Set<String> fuDans = c1Auth.getFuDanSet();
//                Set<String> stems = c1Auth.getStemSet();
//                for (String dept : depts) {
//                    String trim = dept.toLowerCase().trim();
//                    if (deptAndFuDanOrStemListMap.containsKey(trim)) {
//                        List<String> list = deptAndFuDanOrStemListMap.get(trim);
//                        if (null != list && list.size() == 2) {
//                            fuDans.add(list.get(0));
//                            stems.add(list.get(1));
//                        }
//                    }
//                }
//                c1Auth.setFuDanSet(isContains(fuDans, fuDanSet));
//                c1Auth.setStemSet(isContains(stems, stemSet));
//            }
//            return c1AuthList;
//        }
//        return new ArrayList<>();
//    }

//    public static Set<String> isContains(Set<String> fuDans, Set<String> fuDanSet) {
//        // 如果科室的名称是复旦或STEM的标准名称则保留，不是则忽略。fuDanSet是标准的名称集合，fuDans是本次预比对的集合。
//        Set<String> result = new HashSet<>();
//        for (String fuDan : fuDans) {
//            fuDan = fuDan.startsWith("[") && fuDan.endsWith("]") ? fuDan.substring(1, fuDan.length() - 1) : fuDan;
//            if (fuDanSet.contains(fuDan)) {
//                result.add(fuDan);
//            }
//        }
//        return result;
//    }

//    public static void tongYiHospName(String hospTable, String autoId, String field, String user, int min, int max) throws SQLException {
//        // 通义翻译机构的中文名字，最多翻译5次，如果5次仍失败就不再处理了。翻译后的转为实体类，只有在实体有值的时候才认为是成功，不成功则追加一次。翻译的对象为王承伟规范的1732家医院的名称。如果匹配不上，允许阿里推荐一个，推荐的加的有方括号。
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + hospTable);
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + hospTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                try {
//                    List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + hospTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                    System.out.println("\033[31;1m" + format.format(new Date()) + " 读表现在开始：" + startId + " 表名：" + hospTable + Utils.printMemoryStr() + "\033[0m");
//                    for (Entity entry : tableData) {
//                        String info = Utils.getStrField(entry, "info");
//                        String name = Utils.getStrField(entry, "name");
//                        String c1s = Utils.getStrField(entry, "c1s");
//                        String youDao = Utils.getStrField(entry, "you_dao");
//                        int id = Utils.getIntField(entry, autoId);
//                        int end = id > 10 ? Integer.parseInt(Integer.toString(id).substring(Integer.toString(id).length() - 2)) : id;
//                        if (info.contains("\"]") && (name.isEmpty() || "1".equals(name) || "2".equals(name) || "3".equals(name) || "4".equals(name) || "5".equals(name)) && id > 0 && c1s.contains("\"]") && (end >= min && end <= max)) {
//                            try {
//                                List<String> infoList = JSONObject.parseArray(info, String.class);
//                                String join = CollUtil.join(infoList, ", ");
//                                youDao = youDao.length() < 4 ? TransApi.youDaoEnToCnTrans(join) : youDao;
//                                if (youDao.length() > 3) {
//                                    String upData = "";
//                                    // 为什么hospSet包含有道就直接等于有道了？原因是如果有道翻译的名称，与医院标准名称列表的名称相同，就不必要使用大模型了。
//                                    List<String> c1List = JSONObject.parseArray(c1s, String.class);
//                                    String question = c1List.size() == 1 ? cList.reArgs(c1List.get(0)) : join;
//                                    String sendHospJson = TongYiApi.sendUnitJson(question, user);
//                                    JSONArray objects = JSONObject.parseArray(sendHospJson);
//                                    List<En.UnitInfo> unitInfoList = new ArrayList<>();
//                                    if (!objects.isEmpty()) {
//                                        for (Object object : objects) {
//                                            JSONObject jsonObject = JSONObject.parseObject(object.toString());
//                                            String unitName = jsonObject.getString("unit");
//                                            if (null != unitName && unitName.length() > 3) {
//                                                En.UnitInfo unitInfo = new En.UnitInfo();
//                                                unitInfo.setUnit(unitName);
//                                                unitInfo.setInfo(jsonObject.getString("info"));
//                                                unitInfoList.add(unitInfo);
//                                            }
//                                        }
//                                    }
//                                    if (unitInfoList.isEmpty()) {
//                                        upData = name.isEmpty() ? "1" : upData;
//                                        upData = "1".equals(name) ? "2" : upData;
//                                        upData = "2".equals(name) ? "3" : upData;
//                                        upData = "3".equals(name) ? "4" : upData;
//                                        upData = "4".equals(name) ? "5" : upData;
//                                        upData = "5".equals(name) ? "6" : upData;
//                                    } else {
//                                        upData = JSONUtil.toJsonStr(unitInfoList);
//                                    }
//                                    try {
//                                        Db.use().update(Entity.create().set("name", upData).set("you_dao", youDao).set("datetime", LocalDateTime.now()), Entity.create(hospTable).set(autoId, id));
//                                    } catch (SQLException e) {
//                                        e.printStackTrace();
//                                    }
//                                }
//                            } catch (Exception e) {
////                                throw new RuntimeException(e);
//                            }
//                        }
//                    }
//                } catch (SQLException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }

//    public static void updateUnitDeptAuth(String guidelinesTable, String autoId, String field, String deptTable, String hospTable, String basicHospTable, String enBasicDeptTable, String cnBasicDeptTable, String basicUnivCollTable, String htLocationChinaTable) throws SQLException {
//        // 将原始的C1和RP转换为实体类，并将dept和hosp加入翻译列表，供人工加AI翻译后使用。basicHospTable和basicDeptTable是之前翻译的，供本次使用。deptTable和hospTable是本次新产生的，需要人工加AI翻译后再使用。
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Set<String> stemSet = uSet.getStemSet();
//        Set<String> fuDanSet = uSet.getFuDanSet();
//        Set<String> chinaSet = cList.chinaSet();
//        Map<String, List<String>> deptAndFuDanOrStemListMap = new HashMap<>();
//        Guidelines.getEnDeptAndFuDanOrStemListMap(enBasicDeptTable, "id", "info`,`fudan`,`stem", stemSet, fuDanSet, deptAndFuDanOrStemListMap);
//        Guidelines.getCnDeptAndFuDanOrStemListMap(cnBasicDeptTable, "id", "info`,`fudan`,`stem", stemSet, fuDanSet, deptAndFuDanOrStemListMap);
//        deptAndFuDanOrStemListMap = Guidelines.mapSortValueStrLen(deptAndFuDanOrStemListMap);
////        Map<String, List<String>> deptAndFuDanOrStemListMap = getEnDeptAndFuDanOrStemListMap(enBasicDeptTable, "id", "info`,`fudan`,`stem", stemSet, fuDanSet);
////        Map<String, List<String>> cnDeptAndFuDanOrStemListMap = Guidelines.getCnDeptAndFuDanOrStemListMap(cnBasicDeptTable, "id", "info`,`fudan`,`stem", stemSet, fuDanSet);
//        System.out.println(format.format(new Date()) + " deptAndFuDanOrStemListMap.size()：" + deptAndFuDanOrStemListMap.size());
//        Map<List<String>, String> infoAndUnitMap = getInfoAndUnitMap(basicHospTable, "id", "info`,`standard");
//        System.out.println(format.format(new Date()) + " infoAndUnitMap.size()：" + infoAndUnitMap.size());
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + guidelinesTable);
//        Map<String, String> standardMap = new HashMap<>();
//        standardMap.put("department medical", "Department Medical");
//        Map<Set<String>, Set<String>> unitAndSumMap = new HashMap<>();
//        Map<String, Set<String>> deptAndInfoSetMap = new ConcurrentHashMap<>();
//        Map<String, Integer> deptAndSumMap = new ConcurrentHashMap<>();
//        Map<String, String> countryMap = cList.getCountryMap();
//        Set<String> acadSet = uSet.getAcadSet();
//        Set<String> centerSet = uSet.getCenterSet();
//        Set<String> collSet = uSet.getCollSet();
//        Set<String> hospSet = uSet.getHospSet();
//        Set<String> univSet = uSet.getUnivSet();
//        Set<String> removeSet = uSet.getRemoveSet();
//        Set<String> deptSet = uSet.getDeptSet();
//        Set<String> dellSet = uSet.getDellSet();
//        Set<String> notCollSet = cList.getNotCollSet();
//        Set<String> citySet = new HashSet<>();
//        Set<String> subjectSet = cList.getSubjectSet();
//        Set<String> provCitySet = Dept.getProvCitySet(htLocationChinaTable, "id", "prov`,`name", citySet);
//        Map<String, En.Edu> collAndEduMap = Guidelines.getCollAndEduMap(basicUnivCollTable, "id", "info`,`edu", notCollSet);
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + guidelinesTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + guidelinesTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                System.out.println("\033[31;1m" + format.format(new Date()) + " 读表现在开始：" + startId + " 表名：" + guidelinesTable + Utils.printMemoryStr() + "\033[0m");
//                for (Entity entry : tableData) {
//                    List<En.C1Auth> c1List = Utils.getC1List(entry.getStr("C1"));
//                    List<En.C1Auth> rpList = Utils.getRpList(entry.getStr("RP"));
//                    List<En.C1Auth> rpChangeC1 = ChangeRp.rpChangeC1(c1List, rpList);
////                    setC1List(c1List, standardMap, acadSet, centerSet, collSet, hospSet, univSet, removeSet, countryMap, unitAndSumMap, deptAndFuDanOrStemListMap, deptAndSumMap, dellSet, fuDanSet, stemSet, chinaSet, collAndEduMap, provCitySet, citySet, subjectSet, deptAndInfoSetMap);
////                    setC1List(rpChangeC1, standardMap, acadSet, centerSet, collSet, hospSet, univSet, removeSet, countryMap, unitAndSumMap, deptAndFuDanOrStemListMap, deptAndSumMap, dellSet, fuDanSet, stemSet, chinaSet, collAndEduMap, provCitySet, citySet, subjectSet, deptAndInfoSetMap);
//                    int id = Utils.getIntField(entry, autoId);
//                    try {
//                        Db.use().update(Entity.create().set("c1_unit_dept_auth", JSONUtil.toJsonStr(c1List)).set("rp_unit_dept_auth", JSONUtil.toJsonStr(rpChangeC1)), Entity.create(guidelinesTable).set(autoId, id));
//                    } catch (SQLException e) {
//                        e.printStackTrace();
//                    }
//                }
//            }
//        }
////        Db.use().execute("truncate table " + hospTable);
////        unitAndSumMap.keySet().parallelStream().forEach(unitSet -> {
////            Set<String> set = unitAndSumMap.get(unitSet);
////            List<String> infoList = JSONObject.parseArray(JSONUtil.toJsonStr(unitSet).toLowerCase(), String.class);
////            Collections.sort(infoList);
////            String standard = infoAndUnitMap.getOrDefault(infoList, "");
////            try {
////                Db.use().insert(Entity.create(hospTable).set("info", JSONUtil.toJsonStr(unitSet)).set("c1s", JSONUtil.toJsonStr(set)).set("sum", set.size()).set("standard", standard));
////            } catch (SQLException e) {
////                e.printStackTrace();
////            }
////        });
////        Db.use().execute("truncate table " + deptTable);
////        Map<String, List<String>> finalDeptAndFuDanOrStemListMap = deptAndFuDanOrStemListMap;
////        deptAndSumMap.keySet().parallelStream().forEach(dept -> {
////            Set<String> set = deptAndSumMap.get(dept);
////            String fuDan = "";
////            String stem = "";
////            if (finalDeptAndFuDanOrStemListMap.containsKey(dept.toLowerCase().trim())) {
////                List<String> list = finalDeptAndFuDanOrStemListMap.get(dept.toLowerCase().trim());
////                if (null != list && list.size() == 2) {
////                    fuDan = list.get(0);
////                    stem = list.get(1);
////                }
////            }
////            try {
////                Db.use().insert(Entity.create(deptTable).set("info", dept).set("c1s", JSONUtil.toJsonStr(set)).set("sum", set.size()).set("fudan", fuDan).set("stem", stem));
////            } catch (SQLException e) {
////                e.printStackTrace();
////            }
////        });
//    }

    public static void setC1List(List<En.C1Auth> c1List, Map<String, String> standardMap, Set<String> acadSet, Set<String> centerSet, Set<String> collSet, Set<String> hospSet, Set<String> univSet, Set<String> removeSet, Map<String, String> countryMap,
                                 Map<String, Integer> deptAndSumMap, Set<String> dellSet, Set<String> chinaSet, Set<String> provCitySet, Set<String> citySet, Set<String> subjectSet, Map<String, Set<String>> deptAndInfoSetMap,
                                 Map<String, Set<String>> unitAndInfoSetMap, Map<String, Integer> unitAndSumMap, Set<String> toDeptSet, Map<String, En.FuDanStemEdu> fuDanStemEduMap) throws SQLException {
        for (En.C1Auth c1Auth : c1List) {
            // 如果full与info字符串相同，则只保存info的信息，所以当full为空时，取info的信息。在PubMed中，只保存info，而不保存full。
            if (!c1Auth.getFull().isEmpty() && !Pattern.compile("[a-z]").matcher(c1Auth.getFull()).find()) {
                c1Auth.setFull(cList.reArgs(c1Auth.getInfo()));
            }
            String full = ("".equals(c1Auth.getFull()) ? c1Auth.getInfo() : c1Auth.getFull()).replace("ETH, Zurich", "ETH Zurich");
            Set<String> unitSet = new HashSet<>();
            Set<String> deptSet = new HashSet<>();
            int is_cn_hosp = 0;
            int is_cn_univ = 0;
            int is_en_hosp = 0;
            int is_en_univ = 0;
            if (Utils.isContainChinese(full)) {
                boolean isCnHosp = full.contains("医院") || full.contains("疾病预防控制中心") || full.contains("肿瘤防治中心") || full.contains("预防控制中心") || full.contains("医疗救治中心") || full.contains("眼病防治中心") || full.contains("血液病研究所") ||
                        full.contains("传染病防治院") || full.contains("眼科研究所") || full.contains("心肺研究所") || full.contains("肾病研究所") || full.contains("妇幼保健院") || full.contains("妇婴保健院") || full.contains("妇女保健院") ||
                        full.contains("儿科研究所") || full.contains("癌症研究所") || full.contains("诊疗中心") || full.contains("医学中心") || full.contains("医疗中心") || full.contains("眼科中心") || full.contains("卫生中心") || full.contains("体检中心") ||
                        full.contains("临床中心") || full.contains("精神病院") || full.contains("健康中心") || full.contains("急救中心") || full.contains("病研究所") || full.contains("保健中心") || full.contains("癌症中心") || full.contains("防疫站") || full.contains("医 院");
                boolean isCnUniv = full.contains("大学") || full.contains("学院") || full.contains("学校");
                if (isCnHosp || isCnUniv) {
                    Unit.getCnUnit(full, unitSet);
                    Dept.getCnDept(full, provCitySet, deptSet, citySet, unitSet);
                    // 如果没有获取到学科的集合（即部门信息，比如仅有山东大学齐鲁医院，后面没有什么科室信息的），而又属于大学和医院的，对大学的学科加上"临床医学"，即认为大学的附属医院为"临床医学"学科。
                    if (deptSet.isEmpty() && isCnUniv && isCnHosp) {
                        deptSet.add("[univ]" + "临床医学");
                    }
                }
                is_cn_hosp = isCnHosp ? 1 : is_cn_hosp;
                is_cn_univ = isCnUniv ? 1 : is_cn_univ;
            } else {
                boolean isEnUniv = Unit.isUniv(full, univSet, removeSet);
                boolean isEnHosp = Unit.isHosp(full, hospSet, removeSet);
                is_en_hosp = isEnHosp ? 1 : is_en_hosp;
                is_en_univ = isEnUniv ? 1 : is_en_univ;
                if (isEnUniv || isEnHosp) {
                    Set<String> depts = new HashSet<>();
                    Dept.getEnDept(full, depts, subjectSet, removeSet);
                    Set<String> units = Unit.getEnUnit(full, standardMap, acadSet, centerSet, collSet, hospSet, univSet, removeSet, dellSet);
                    String univ = "";
                    String hosp = "";
                    // 如果大学拿到了标准的大学名称，比如："karolinska institute"，那么，可以让大学集合(units)只要这一个标准的名字，并从depts集合中移除。医院也作相同的操作，大学的名字主要要了大学及学院，医院的名字主要要了医院和诊所。
                    if (!units.contains("Guangdong") && !units.contains("Beijing") && !units.contains("Chongqing") && !units.contains("Dalian") && !units.contains("Fuzhou") && !units.contains("Hubei") && !units.contains("Jilin") && !units.contains("Shanghai") && !units.contains("Wuhan")
                            && !units.contains("Xiamen") && !units.contains("Baoan") && !units.contains("China") && !units.contains("Dongguan") && !units.contains("East China") && !units.contains("Guangzhou") && !units.contains("Heyuan") && !units.contains("Shandong") &&
                            !units.contains("Shenyang") && !units.contains("Shenzhen") && !units.contains("Shunde") && !units.contains("Taiwan") && !units.contains("USA") && !units.contains("Xuzhou") && !units.contains("Zhuhai")) {
                        for (String s : units) {
                            String t = " " + s.toLowerCase().trim() + " ";
                            boolean isUniv = t.contains(" universidad ") || t.contains("universidade") || t.contains(" université ") || t.contains("universitario") || t.contains(" universe ") || t.contains(" universitas ") || t.contains(" università ") || t.contains("universitaire") ||
                                    t.contains(" univ ") || t.contains(" universität ") || t.contains(" universal ") || t.contains(" universiti ") || t.contains(" universitat ") || t.contains(" universitário ") || t.contains(" universitaria ") || t.contains(" universitari ") ||
                                    t.contains(" universiteit ") || t.contains("karolinska institute") || t.contains("trinity college dublin") || t.contains("royal institute technol") || t.contains("korea advance(d) institute science & technol") || t.contains(" ip paris ") ||
                                    t.contains("institute polytech paris") || t.contains("london school economy") || t.contains("calif institute technol") || t.contains(" eth zurich ") || t.contains("ecole polytech federal lausanne") || t.contains("swiss federal institute technol") ||
                                    t.contains("massachusetts institute technol") || t.contains(" iit delhi ") || t.contains("university") || t.contains("korea adv inst sci & technol") || Unit.isContainsAbbr(full);
                            boolean isHosp = t.contains("mayo clinical") || t.contains("cleveland clinical") || t.contains("memorial sloan kettering cancer center") || t.contains("md anderson cancer center") || t.contains("anderson cancer center") || t.contains("md anderson") ||
                                    t.contains("walter reed nacional military medicinal center") || t.contains("walter reed nacional military medical center") || t.contains("nacional naval medical center") || t.contains("walter reed nacional medical center") ||
                                    t.contains("university health network") || t.contains("hospital") || t.contains("charite university medical berlin") || t.contains("ronald reagan ucla medical center") || t.contains("sheba medical center") ||
                                    t.contains("all india institute medical science") || t.contains("asan medical center") || t.contains("beth israel deaconess medical center") || t.contains("samsung medical center") || t.contains("heart center leipzig") ||
                                    t.contains("deutsches herzzentrum berlin") || t.contains("cedars sinai medical center") || t.contains("nacional heart center singapore") || t.contains("policlin university a gemelli") || t.contains("university navarra clinical") ||
                                    t.contains("fundacion irccs ist neurol carlo besta") || t.contains("lmu klinikum") || t.contains("clinical barcelona") || t.contains("sunnybrook health science center") || t.contains("grande ospedale metropolitano niguarda") ||
                                    t.contains("gustave roussy") || t.contains("ist europeo oncol") || t.contains("princess margaret cancer center") || t.contains("dana farber cancer institute") || t.contains("peter maccallum cancer center") || t.contains("institute curie") ||
                                    t.contains("schulthess clinical") || t.contains("helios endo klinik hamburg") || t.contains("ist ortopedico rizzoli") || t.contains("ospedale pediatrico bambino gesu") || t.contains("nacional jewish health") || t.contains("thoraxklinik heidelberg") ||
                                    t.contains("hosptial") || t.contains("hospices") || t.contains(" hospita ") || t.contains(" hospice ") || full.contains("MSKCC") || full.contains("MDACC") || full.contains("WRNMMC") || full.contains("INCOR");
                            if (isUniv && !isHosp) {
                                univ = s;
                            }
                            if (!isUniv && isHosp) {
                                hosp = s;
                            }
                        }
                    }
                    // 如果有标准的大学名字，且不含医院，则只要标准的大学的名称，并把大学的名称从科室中移除（虽然大概率不会出现在科室中）。医院也作这样的操作。
                    if (!univ.isEmpty() && !isEnHosp) {
                        unitSet.add(univ.toLowerCase());
                        depts.remove(univ);
                    } else if (!hosp.isEmpty() && !isEnUniv) {
                        unitSet.add(hosp.toLowerCase());
                        depts.remove(hosp);
                    } else {
                        for (String s : units) {
                            unitSet.add(s.toLowerCase());
                            depts.remove(s);
                        }
                    }
                    // 部分学院的单词，也会被识别为大学，比如："school medical"，在此给予移除。
                    if (isEnUniv) {
                        for (String toDept : toDeptSet) {
                            if (unitSet.contains(toDept)) {
                                unitSet.remove(toDept);
                                deptSet.add("[univ]" + toDept);
                            }
                        }
                    }
                    for (String s : depts) {
                        if (isEnUniv) {
                            deptSet.add("[univ]" + s.toLowerCase());
                        }
                        if (isEnHosp) {
                            deptSet.add("[hosp]" + s.toLowerCase());
                        }
                    }
                    if (deptSet.isEmpty() && isEnUniv && isEnHosp) {
                        deptSet.add("[univ]" + "临床医学");
                    }
                }
            }
            String country = Country.getCountry(full, countryMap, chinaSet);
            c1Auth.setUnitSet(unitSet);
            c1Auth.setCountry(country);
            c1Auth.setDeptSet(deptSet);
            for (String original : deptSet) {
                String dept = (original.startsWith("[univ]") || original.startsWith("[hosp]")) ? original.substring("[hosp]".length()) : original;
                String trim = dept.toLowerCase().trim();
                if (fuDanStemEduMap.containsKey(trim)) {
                    En.FuDanStemEdu fuDanStemEdu = fuDanStemEduMap.get(trim);
                    if (!fuDanStemEdu.getFuDan().isEmpty()) {
                        c1Auth.getFuDanSet().add(fuDanStemEdu.getFuDan());
                    }
                    if (!fuDanStemEdu.getStem().isEmpty()) {
                        c1Auth.getStemSet().add(fuDanStemEdu.getStem());
                    }
                    if (!fuDanStemEdu.getEdu().getSubject().isEmpty()) {
                        c1Auth.getEduSet().add(fuDanStemEdu.getEdu());
                    }
                }
                Dept.putStrSetStrLen(original, full, deptAndInfoSetMap);
                deptAndSumMap.compute(original, (key, value) -> value != null ? (value + 1) : 1);
            }
            if (!unitSet.isEmpty()) {
                String unit = CheckUnit.listToUnit(new ArrayList<>(unitSet));
                Dept.putStrSetStrLen(unit, full, unitAndInfoSetMap);
                unitAndSumMap.compute(unit, (key, value) -> value != null ? (value + 1) : 1);
            }
            // 以下是拆分单位和科室的细节，用于验证，平时可以不用。
//            String hospUnivDeptTable = "scholar_25_02.test_hosp_or_univ_dept_unit";
//            try {
//                Db.use().insert(Entity.create(hospUnivDeptTable)
//                        .set("info", full).set("is_cn_hosp", is_cn_hosp).set("is_cn_univ", is_cn_univ).set("is_en_hosp", is_en_hosp).set("is_en_univ", is_en_univ)
//                        .set("dept_c1s", JSONUtil.toJsonStr(deptSet)).set("unit_c1s", JSONUtil.toJsonStr(unitSet)).set("datetime", LocalDateTime.now()));
//            } catch (SQLException e) {
//                e.printStackTrace();
//            }
        }
    }

//    public static Map<List<String>, String> getInfoAndUnitMap(String basicHospTable, String autoId, String field) throws SQLException {
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + basicHospTable);
//        Map<List<String>, String> infoAndUnitMap = new HashMap<>();
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + basicHospTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + basicHospTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                for (Entity entry : tableData) {
//                    String info = entry.getStr("info");
//                    String standard = entry.getStr("standard");
//                    if (null != info && info.contains("\"]") && null != standard && standard.length() > 3) {
//                        List<String> infoList = JSONObject.parseArray(info.toLowerCase(), String.class);
//                        Collections.sort(infoList);
//                        infoAndUnitMap.put(infoList, standard);
//                    }
//                }
//            }
//        }
//        return infoAndUnitMap;
//    }

//    public static Map<String, En.Edu> getCollAndEduMap(String basicUnivCollTable, String autoId, String field, Set<String> notCollSet) throws SQLException {
//        // 从以前曾经规范的科室表basicDeptTable中，获取各科室名称相对应的复旦和STEM的标准名称，如果名称上有方括号给予去除，并转换成小写。
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + basicUnivCollTable);
//        Map<String, En.Edu> infoAndEduMap = new HashMap<>();
//        Map<String, En.Edu> eduSubJectMap = Dept.getEduSubJectMap();
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + basicUnivCollTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + basicUnivCollTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                for (Entity entry : tableData) {
//                    String info = entry.getStr("info");
//                    String edu = entry.getStr("edu");
//                    if (null != info && info.length() > 5 && null != edu && edu.contains("subject")) {
//                        String s = info.toLowerCase().trim();
//                        if (!notCollSet.contains(s)) {
//                            infoAndEduMap.put(info.toLowerCase().trim(), JSONObject.parseObject(edu, En.Edu.class));
//                        }
//                    }
//                }
//            }
//        }
//        for (Map.Entry<String, En.Edu> entry : eduSubJectMap.entrySet()) {
//            infoAndEduMap.put(entry.getKey().trim(), entry.getValue());
//        }
//        // 增加最长的科室排在Map的最前面，用于匹配时，优先匹配上最长的科室名称，之后即可停止，以减少计算量。
//        Map<String, Integer> infoAndLenMap = new HashMap<>();
//        for (Map.Entry<String, En.Edu> entry : infoAndEduMap.entrySet()) {
//            String info = entry.getKey();
//            infoAndLenMap.put(info, info.length());
//        }
//        // 对Map的值进行排序，此排序为最大的在前面，输入一个map，再返回一个排序后的新map，String, Integer类型。
//        Map<String, Integer> sortValueStrIntMap = Utils.mapSortValueStrInt(infoAndLenMap);
//        Map<String, En.Edu> resultMap = new LinkedHashMap<>();
//        for (Map.Entry<String, Integer> entry : sortValueStrIntMap.entrySet()) {
//            String info = entry.getKey();
//            if (infoAndEduMap.containsKey(info)) {
//                resultMap.put(info, infoAndEduMap.get(info));
//            }
//        }
//        return resultMap;
//    }

//    public static void getEnDeptAndFuDanOrStemListMap(String enBasicDeptTable, String autoId, String field, Set<String> stemSet, Set<String> fuDanSet, Map<String, List<String>> deptAndFuDanOrStemListMap) throws SQLException {
//        // 从以前曾经规范的科室表basicDeptTable中，获取各科室名称相对应的复旦和STEM的标准名称，如果名称上有方括号给予去除，并转换成小写。
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + enBasicDeptTable);
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + enBasicDeptTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + enBasicDeptTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                for (Entity entry : tableData) {
//                    // 论文中的dept的不同写法
//                    String info = entry.getStr("info");
//                    if (null != info && info.length() > 5) {
//                        String fuDan = getFuDanOrStemDept(entry.getStr("fudan"), fuDanSet);
//                        String stem = getFuDanOrStemDept(entry.getStr("stem"), stemSet);
//                        if (!fuDan.isEmpty() || !stem.isEmpty()) {
//                            // 这里deptList分别保存了复旦和STEM的名称，也可以使用实体类，本次使用了list，获取时分别取0和1。
//                            List<String> deptList = new ArrayList<>();
//                            deptList.add(fuDan);
//                            deptList.add(stem);
//                            deptAndFuDanOrStemListMap.put(info.toLowerCase().trim(), deptList);
//                        }
//                    }
//                }
//            }
//        }
//    }

//    public static void getCnDeptAndFuDanOrStemListMap(String cnBasicDeptTable, String autoId, String field, Set<String> stemSet, Set<String> fuDanSet, Map<String, List<String>> deptAndFuDanOrStemListMap) throws SQLException {
//        // 从以前曾经规范的科室表basicDeptTable中，获取各科室名称相对应的复旦和STEM的标准名称，如果名称上有方括号给予去除，并转换成小写。
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + cnBasicDeptTable);
////        Map<String, List<String>> cnDeptAndFuDanOrStemListMap = new HashMap<>();
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + cnBasicDeptTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + cnBasicDeptTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                for (Entity entry : tableData) {
//                    // 论文中的dept的不同写法
//                    String info = entry.getStr("info");
//                    if (null != info && info.length() > 1 && (info.endsWith("科") || info.endsWith("中心") || info.endsWith("门诊") || info.endsWith("部") || info.endsWith("区") || info.endsWith("办") || info.endsWith("处") || info.endsWith("房") ||
//                            info.endsWith("室") || info.endsWith("组") || info.endsWith("内分泌") || info.endsWith("检验系") || info.endsWith("耳鼻咽喉头颈外科病院") || info.endsWith("神经内科ICU") || info.endsWith("急诊ICU") || info.endsWith("神经外科ICU") ||
//                            info.endsWith("心外ICU") || info.endsWith("中心ICU") || info.endsWith("综合ICU") || info.endsWith("心内科CCU") || info.endsWith("门急诊") || info.endsWith("急诊") || info.endsWith("消化病院") || info.endsWith("耳鼻咽喉") ||
//                            info.endsWith("外科ICU") || info.endsWith("妇幼保健院") || info.endsWith("中医系") || info.endsWith("心胸外科ICU") || info.endsWith("胃肠外科中心MCQ团队") || info.endsWith("耳鼻喉") || info.endsWith("放射") || info.endsWith("核医学") ||
//                            info.endsWith("内科ICU") || info.endsWith("ＩＣＵ") || info.endsWith("心血管内科CCU") || info.endsWith("普外") || info.endsWith("麻醉") || info.endsWith("口腔医学院") || info.endsWith("血库") || info.endsWith("心外科ICU") ||
//                            info.endsWith("心内") || info.endsWith("神经") || info.endsWith("心外") || info.endsWith("外科学系") || info.endsWith("所"))) {
//                        String fuDan = getFuDanOrStemDept(entry.getStr("fudan"), fuDanSet);
//                        String stem = getFuDanOrStemDept(entry.getStr("stem"), stemSet);
//                        if (!fuDan.isEmpty() || !stem.isEmpty()) {
//                            // 这里deptList分别保存了复旦和STEM的名称，也可以使用实体类，本次使用了list，获取时分别取0和1。
//                            List<String> deptList = new ArrayList<>();
//                            deptList.add(fuDan);
//                            deptList.add(stem);
//                            deptAndFuDanOrStemListMap.put(info.toLowerCase().trim(), deptList);
//                        }
//                    }
//                }
//            }
//        }
//    }

    public static Map<String, En.FuDanStemEdu> getFuDanStemEduMap(String basicHospUnivDeptTable, String autoId, String field) throws SQLException {
        // 从以前曾经规范的科室表basicDeptTable中，获取各科室名称相对应的复旦和STEM的标准名称，如果名称上有方括号给予去除，并转换成小写。
        int onePageNum = 1000;
        Map<String, En.FuDanStemEdu> fuDanStemEduMap = new HashMap<>();
        Set<String> stemSet = uSet.getStemSet();
        Set<String> fuDanSet = uSet.getFuDanSet();
        int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + basicHospUnivDeptTable).intValue();
        if (tableMax > 0) {
            Collection<Integer> tableList = new ArrayList<>();
            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
            for (Integer startId : tableList) {
                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + basicHospUnivDeptTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
                for (Entity entry : tableData) {
                    // 论文中的dept的不同写法
                    String info = entry.getStr("info");
                    if (null != info && info.length() > 1) {
                        String fuDan = getFuDanOrStemDept(entry.getStr("fudan"), fuDanSet);
                        String stem = getFuDanOrStemDept(entry.getStr("stem"), stemSet);
                        String edu = Utils.getStrField(entry, "edu");
                        if (!fuDan.isEmpty() || !stem.isEmpty() || edu.contains("category")) {
                            En.FuDanStemEdu fuDanStemEdu = new En.FuDanStemEdu();
                            fuDanStemEdu.setStem(stem);
                            fuDanStemEdu.setFuDan(fuDan);
                            if (edu.contains("category")) {
                                fuDanStemEdu.setEdu(JSONObject.parseObject(edu, En.Edu.class));
                            }
                            fuDanStemEduMap.put(info.toLowerCase().trim(), fuDanStemEdu);
                        }
                    }
                }
            }
        }
        return fuDanStemEduMap;
    }

//    public static Map<String, List<String>> mapSortValueStrLen(Map<String, List<String>> deptAndFuDanOrStemListMap) {
//        // 增加最长的科室排在Map的最前面，用于匹配时，优先匹配上最长的科室名称，之后即可停止，以减少计算量。
//        Map<String, Integer> cnDeptAndLenMap = new HashMap<>();
//        for (Map.Entry<String, List<String>> entry : deptAndFuDanOrStemListMap.entrySet()) {
//            String dept = entry.getKey();
//            cnDeptAndLenMap.put(dept, dept.length());
//        }
//        // 对Map的值进行排序，此排序为最大的在前面，输入一个map，再返回一个排序后的新map，String, Integer类型。
//        Map<String, Integer> sortValueStrIntMap = Utils.mapSortValueStrInt(cnDeptAndLenMap);
//        Map<String, List<String>> resultMap = new LinkedHashMap<>();
//        for (Map.Entry<String, Integer> entry : sortValueStrIntMap.entrySet()) {
//            String dept = entry.getKey();
//            if (deptAndFuDanOrStemListMap.containsKey(dept)) {
//                resultMap.put(dept, deptAndFuDanOrStemListMap.get(dept));
//            }
//        }
//        return resultMap;
//    }

    public static String getFuDanOrStemDept(String fuDan, Set<String> fuDanOrStemSet) {
        if (null != fuDan && fuDan.contains("info")) {
            List<En.UnitInfo> unitInfoList = JSONObject.parseArray(fuDan, En.UnitInfo.class);
            for (En.UnitInfo unitInfo : unitInfoList) {
                String dept = unitInfo.getUnit().trim();
                if (dept.length() > 1 && fuDanOrStemSet.contains(dept)) {
                    return dept;
                }
            }
        } else if (null != fuDan && fuDan.length() > 1 && fuDanOrStemSet.contains(fuDan.trim())) {
            return fuDan.trim();
        }
        return "";
    }

//    public static void insertReferenceTable(String citationTable, String autoId, String field, String referenceTable, int min, int max) throws SQLException {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        int onePageNum = 100000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + citationTable);
//        Map<Integer, Set<Integer>> pidAndPidSetMap = new HashMap<>();
//        int maxId = 0;
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + citationTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + citationTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                System.out.println("\033[31;1m" + format.format(new Date()) + " 读表现在开始：" + startId + " 表名：" + citationTable + Utils.printMemoryStr() + "\033[0m");
//                for (Entity entry : tableData) {
//                    Integer pid = entry.getInt("pid");
//                    String citationId = entry.getStr("citation_id");
//                    if (null != pid && pid > 0 && null != citationId && !citationId.isEmpty()) {
//                        String[] split = citationId.replace(" ", "").trim().split(",");
//                        for (String ids : split) {
//                            if (NumberUtil.isInteger(ids)) {
//                                int id = Integer.parseInt(ids);
//                                maxId = Math.max(maxId, id);
//                                if (id >= min && id < max) {
//                                    putIntSetIntMap(pidAndPidSetMap, id, pid);
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//        }
//        System.out.println("maxId: " + maxId);
//        pidAndPidSetMap.keySet().parallelStream().forEach(pid -> {
//            Set<Integer> idSet = pidAndPidSetMap.get(pid);
//            String ids = CollUtil.join(idSet, ",");
//            try {
//                Db.use().insert(Entity.create(referenceTable).set("pid", pid).set("reference_total", idSet.size()).set("reference_id", ids));
//            } catch (SQLException e) {
//                e.printStackTrace();
//            }
//        });
//    }

//    public static void putIntSetIntMap(Map<Integer, Set<Integer>> finishAidListSetMap, int max, int min) {
//        finishAidListSetMap.compute(max, (k, v) -> {
//            if (v == null) {
//                v = new ConcurrentHashSet<>();
//            }
//            v.add(min);
//            return v;
//        });
//    }

//    public static void insertGuidelinesTable(String summaryTable, String autoId, String field, String filePath, String guidelinesTable) throws SQLException {
//        Set<Integer> pmIdSet = new HashSet<>();
//        Set<String> doiSet = new HashSet<>();
//        List<String> list = FileUtil.readLines(filePath, "utf-8");
//        for (String s : list) {
//            String[] split = s.split("\\|");
//            if (split.length == 2) {
//                String pm = split[0];
//                String doi = split[1];
//                if (NumberUtil.isInteger(pm)) {
//                    pmIdSet.add(Integer.parseInt(pm));
//                }
//                if (doi.startsWith("10.")) {
//                    doiSet.add(doi.toLowerCase().trim());
//                }
//            }
//        }
//        System.out.println(pmIdSet.size() + "--" + doiSet.size());
//        String save = "`cscd_id`,`ncbi_id`,`yiigle_id`,`wos_id`,`weipu_id`,`wanfang_id`,`cnki_id`,`key_word_list`,`pm_ut_doi_list`,`journal`,`aid`,`citation_quota`,`reference_quota`,`ti_key`,`ab_key`,`kw_key`,`abb_word`,`zky_dalei`,`jcr_if`,`year`,`title`," +
//                "`keyword`,`ab`,`mesh`,`jid`,`discussion`,`results`,`methods`,`background`,`c1_list`,`c1_unit_list`,`rp_list`,`rp_unit_list`,`cite`,`cn_ti`,`cn_ab`,`cn_kw`,`cn_type`,`pt`,`cn_country`,`cn_unit`,`is_cns`,`cn_fund`,`cn_country_1`,`cn_unit_1`," +
//                "`unit_standard`,`dept_standard`,`pmId`,`ut`,`doi`,`nlmId`,`cite_score`,`jcr_quartile`,`fund`,`fund_list`,`fund_standard`,`method_info`,`trans_ok`,`drug_gene_pathway_disease`,`auth`,`sort_auth`,`info`,`is_retraction`,`is_china`,`cn_discussion`," +
//                "`cn_results`,`cn_methods`,`cn_background`,`cs_sjr`,`is_beida`,`is_cs`,`is_cscd`,`is_jcr`,`is_pubmed`,`is_tjy`,`is_yiigle`,`is_zky`,`zky_subject`,`is_core`,`mail_list`";
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        int onePageNum = 100000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + summaryTable);
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + summaryTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + summaryTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
//                System.out.println("\033[31;1m" + format.format(new Date()) + " 读表现在开始：" + startId + " 表名：" + summaryTable + Utils.printMemoryStr() + "\033[0m");
//                for (Entity entry : tableData) {
//                    Integer id = entry.getInt(autoId);
//                    String doi = entry.getStr("doi");
//                    doi = null == doi ? "" : doi.toLowerCase().trim();
//                    if (null != id && id > 0 && (pmIdSet.contains(entry.getInt("pmId")) || doiSet.contains(doi))) {
//                        Db.use().execute("insert into " + guidelinesTable + "(" + save + ") select " + save + " from " + summaryTable + " where " + autoId + " = " + id + ";");
//                    }
//                }
//            }
//        }
//    }

//    public static String getDept(String full) {
//        String[] split = full.replace("；", ", ").replace("。", ", ").replace("，", ", ").replace("; ", ", ").replace(". ", ", ").split(", ");
//        for (String s : split) {
//            String t = s.toLowerCase().trim();
//            if ((t.contains(" department ") || t.startsWith("department ") || t.endsWith(" department")) && s.length() > 13 && !t.contains("university") && !t.contains("hospital") && !"department medical".equals(t)) {
//                return s;
//            }
//        }
//        return full;
//    }

//    public static Set<String> getUnitSet(En.C1Split c1Split) {
//        if (!c1Split.getUnivSet().isEmpty()) {
//            return c1Split.getUnivSet();
//        } else if (!c1Split.getHospSet().isEmpty()) {
//            return c1Split.getHospSet();
//        } else if (!c1Split.getAcademySet().isEmpty()) {
//            return c1Split.getAcademySet();
//        } else if (!c1Split.getCollSet().isEmpty()) {
//            return c1Split.getCollSet();
//        } else if (!c1Split.getOtherSet().isEmpty()) {
//            return c1Split.getOtherSet();
//        }
//        return new HashSet<>();
//    }

//    public static void putUnitAndSumMap(Map<Set<String>, Set<String>> unitAndSumMap, Set<String> univSet, String full) {
//        if (null != univSet && !univSet.isEmpty() && null != full && full.length() > 5) {
//            unitAndSumMap.compute(univSet, (k, v) -> {
//                if (v == null) {
//                    v = new ConcurrentHashSet<>();
//                }
//                v.add(full);
//                return v;
//            });
//        }
//    }


}
